﻿using Microsoft.AspNetCore.Mvc;
using System;
using System.Threading.Tasks;
using YaAppoint.TextTemplates;

namespace YaAppoint.Web.Controllers
{
    public class TextTemplateController(ITextTemplateAppService textTemplateAppService) : Controller
    {
        private readonly ITextTemplateAppService _textTemplateAppService= textTemplateAppService;

        /// <summary>
        /// 加载模板类型选型
        /// </summary>
        [HttpGet("/api/text-template/get-type-options")]
        public  IActionResult GetTypeOptions()
        {
            return new JsonResult(_textTemplateAppService.GetTypeOptions());
        }


        /// <summary>
        /// 获取模板列表
        /// </summary>
        [HttpGet("/api/text-template/get-list")]
        public async Task<IActionResult> GetTemplateList(string? filterName,TemplateType? filterType) 
        {
            return new JsonResult(await _textTemplateAppService.GetTemplateList(filterName, filterType));
        }

        /// <summary>
        /// 获取模板详情
        /// </summary>
        [HttpGet("/api/text-template/get")]
        public async Task<IActionResult> GetDetail(Guid id)
        {
            return new JsonResult(await _textTemplateAppService.GetDetail(id));
        }

        /// <summary>
        /// 删除模板
        /// </summary>
        [HttpGet("/api/text-template/delete")]
        public async Task<IActionResult> Delete(Guid id)
        {
            return new JsonResult(await _textTemplateAppService.Delete(id));
        }

        /// <summary>
        /// 提交新建
        /// </summary>
        [HttpPost("/api/text-template/submit-create")]
        public async Task<IActionResult> SubmitCreate([FromBody] CreateTextTemplateDto dto)
        {
            return new JsonResult(await _textTemplateAppService.SubmitCreate(dto));
        }


        /// <summary>
        /// 提交编辑
        /// </summary>
        [HttpPost("/api/text-template/edit-submit")]
        public async Task<IActionResult> SubmitEdit([FromBody]TextTemplateDto dto)
        {
            return new JsonResult(await _textTemplateAppService.SubmitEdit(dto));
        }
    }
}
